package com.situ.firmadmin.controller;


import com.situ.firmadmin.pojo.Auth;
import com.situ.firmadmin.pojo.Dept;
import com.situ.firmadmin.pojo.query.DeptQuery;
import com.situ.firmadmin.service.IDeptService;
import com.situ.firmadmin.util.PageResult;
import com.situ.firmadmin.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/dept")
public class DeptController {
    @Autowired
    private IDeptService deptService;

    @RequestMapping("/selectAll")
    public Result selectAll(){
        List<Dept> list = deptService.selectAll();
        return Result.ok(list);
    }

    @GetMapping("/list")
    public Result selectByPage(DeptQuery deptQuery){
        PageResult pageResult=deptService.selectByPage(deptQuery);
        Map<String,Object> map=new HashMap<>();
        map.put("total",pageResult.getCount());
        map.put("list",pageResult.getData());
        return Result.ok(map);
    }

    @PostMapping("/add")
    public Result insert(@RequestBody Dept dept){
        deptService.insert(dept);
        return Result.ok("添加成功！");
    }

    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id){
        Dept dept=deptService.selectById(id);
        return Result.ok(dept);
    }

    @PutMapping("/update")
    public Result update(@RequestBody Dept dept){
        deptService.update(dept);
        return Result.ok("修改成功！");
    }

    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id){
        deptService.deleteById(id);
        return Result.ok("删除成功！");
    }

    @DeleteMapping("/deleteAll/{ids}")
    public Result deleteAll(@PathVariable Integer[] ids){
        deptService.deleteAll(ids);
        return Result.ok("删除成功！");
    }
    
    @PutMapping("/updateStatus/{id}/{status}")
    public Result updateStatus(@PathVariable Integer id, @PathVariable Integer status) {
        Dept dept=new Dept();
        dept.setId(id);
        dept.setStatus(status);
        deptService.updateStatus(dept);
        return Result.ok("修改成功！");
    }
}
